//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

class Person {
    var name:String!{
        didSet{
            print("didSet \(String(describing: name))")
            name = "xiaoming"
            print("new didSet \(name)")
        }
        willSet{
            self.name = newValue
            print("willSet \(name)")
        }
    }
}

let firstName = Person()
print(firstName.name)
firstName.name = "xiaohong"
print(firstName.name)
print(firstName.name)


class BaseView:UIView{
    
    var testlabel:UILabel!{
        willSet{
            print("testLabel didSet")
//            self.testlabel.textColor = UIColor.red
        }
        
    }
    
    override func setNeedsDisplay() {
        
        print("setNeedsDisplay")
        
        self.backgroundColor = UIColor.white
        
        testlabel = UILabel(frame: CGRect(x: 10, y: 10, width: 100, height: 30))
        testlabel.text = "ssss"
        self.addSubview(testlabel)
        
    }
    
    override init(frame: CGRect) {
        print("super init")
        super.init(frame: frame)
        print("sub init")
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

let baseView = BaseView(frame: CGRect(x: 0, y: 0, width: 500, height: 300))
//print(baseView.testlabel.text!)
baseView.testlabel.text = "aaaaaa"
print(baseView.testlabel.text!)
baseView


